﻿using FPSO.Models.Constant;
using System;
using System.Globalization;
using System.Windows.Data;

namespace FPSO.HMI.Converter
{
    /// <summary>
    /// 通过舱室ID得到舱室名
    /// </summary>
    class TankIdConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return TankConstant.GetTankName((string)value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// 通过任务状态ID得到名称
    /// </summary>
    class TaskStateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return TaskStateConstant.GetStateName(System.Convert.ToInt32(value));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// 通过任务启动类型ID获取名称
    /// </summary>
    class TaskStartTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return TaskStartTypeConstant.GetStartTypeName(System.Convert.ToInt32(value));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// 使用耗时
    /// </summary>
    class UseTimeConverter : IMultiValueConverter
    {
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime startTime = System.Convert.ToDateTime(value[0]);
            DateTime endTime = System.Convert.ToDateTime(value[1]);
            return (endTime - startTime).TotalHours.ToString("f1");
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (System.Convert.ToDateTime(value).ToString("yyyy-MM-dd HH:mm:ss"));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
